#include "diagnose.h"


int disk_usage(void)
{
    unsigned long total;
    unsigned long free;
    int rtn;
    struct statvfs disk;

    rtn = statvfs("/home", &disk);
    total = disk.f_bsize * disk.f_blocks / 1024;
    free = disk.f_bsize * disk.f_bavail / 1024;
    //printf("RTN=%d, total:%ld free:%ld\n", rtn, total, free);
    return free * 100 / total;
}

void tempr_type_get(int idx, char* type)
{
    ifstream file;
    string path;

    path = SYSFS_THERMAL + to_string(idx) + "/type";
    file.open(path);
    file >> type;
    file.close();
}

int cpu_tempr_get(int idx)
{
    ifstream file;
    string path;
    char tmpr[10];

    path = SYSFS_THERMAL + to_string(idx) + "/temp";
    file.open(path);
    file >> tmpr;
    file.close();
    return std::stoi(tmpr);
}
#if MAIN_RUN
int main(void)
{
    char type[50];    
    disk_usage();

    for(int i=0; i<6; i++)
    {
        tempr_type_get(i, type);
        cout << type << ":" << cpu_tempr_get(i) << endl;//tempr/1000为真实温度
    }
}
#endif
